package test01.yan.t5;

import java.io.*;
import java.util.Scanner;

public class AvarPrice {
    public static void main(String[] args) throws IOException {
        File fRead = new File("src\\test01\\Resource\\goods.txt");
        File fWrite = new File("src\\test01\\Resource\\goodsOut.txt");
        Writer out = new FileWriter(fWrite,true);
        BufferedWriter bw = new BufferedWriter(out);
        Reader in = new FileReader(fRead);
        BufferedReader bR = new BufferedReader(in);
        String str;
        int cnt=0;
        double Price = 0;
        while((str = bR.readLine())!=null)
        {
            Price = getPrice(str);
            if(Price!=0)cnt++;
        }
        System.out.println(Price/cnt);
        bR.close();
        bw.close();
    }

    private static double getPrice(String str) {
        Scanner sc = new Scanner(str);
        sc.useDelimiter("[^0-9.]+");
        double num = 0;
        while (sc.hasNext()) {
            try {
                num = sc.nextDouble();
            } catch (Exception e) {
                String t = sc.next();
            }
        }
        return num;
    }
}
